﻿
using AutoMapper;
using Expression_Test;
using Expression_Test.ExpressionGeneric;
using Expression_Test.ExpressionGeneric.ExpressionAttribute;
using Expression_Test.Reflection;
using Microsoft.Extensions.DependencyInjection;
using System.Diagnostics;

public class Program
{
    /// <summary>
    /// 循环次数
    /// </summary>
    private static int num = 1000;
    //示例对象
    private readonly static Student student = new Student()
    {
        Id = 1,
        Name = "张三"
    };
    public static void Main(string[] args)
    {
        AutoMapper.MapperConfiguration config = new AutoMapper.MapperConfiguration(mce =>
        {
            mce.AddMaps(new string[] { "Expression_Test" });//添加程序集中包含的映射定义。寻找AutoMapper.Profile 【Expression_Test】程序集名称，也就是 AutoMapperProfiles所在的位置)

        });
        var mapper = config.CreateMapper();


        ////AutoMapper 转换
        //new Thread(() =>
        //{
        //    for (int i = 0; i < 2; i++)
        //    {

        //        Stopwatch stopwatch = new Stopwatch();
               
        //        stopwatch.Restart();
        //        DTO_Test.AutoMapperTran(mapper, num, student);
        //        stopwatch.Stop();
        //        Console.WriteLine($"AutoMapper运行时长:{stopwatch.Elapsed}");



        //    }
        //}).Start();

       

        //表达式转换
        new Thread(() =>
        {
            ExpressionGenericMapper<Student, StudentDTO>.Trans(student);//初始化一下
            for (int i = 0; i < 2; i++)
            {
                Stopwatch stopwatch = new Stopwatch();
               
                stopwatch.Start();
                DTO_Test.ExpressionTran(num, student);
                stopwatch.Stop();
                Console.WriteLine($"表达式树时长:{stopwatch.Elapsed}");
            }

        }).Start();

        //原生转换
        new Thread(() =>
        {
            Stopwatch stopwatch = new Stopwatch();
            for (int i = 0; i < 2; i++)
            {
                stopwatch.Restart();
                DTO_Test.ProtoTran(num, student);
                stopwatch.Stop();
                Console.WriteLine($"原生运行时长:{stopwatch.Elapsed}");
            }

        }).Start();



        ////反射转换
        //new Thread(() =>
        //{
        //    Stopwatch stopwatch = new Stopwatch();
        //    for (int i = 0; i < 2; i++)
        //    {
        //        stopwatch.Start();
        //        DTO_Test.ReflectionTran(num, student);
        //        stopwatch.Stop();
        //        Console.WriteLine($"反射运行时长:{stopwatch.Elapsed}");
        //    }

        //}).Start();



        Console.ReadLine();
    }



    public class Student
    {
        public int Id { get; set; }

        public string Name { get; set; }
    }

    public class StudentDTO
    {
        public int Id { get; set; }
        public string Name { get; set; }
    }
}